This section provides background information related to the present disclosure which is not necessarily prior art.
In a digital TV system, an encoder at a transmitting end encodes an audio analog signal or a video analog signal into an audio frame, or a video frame, which is decoded by a decoder at a receiving end. In order ensure normal operation of the encoder at the transmitting end and the decoder at the receiving end, the encoder and the decoder need to be kept consistent in frequency and phase.
Possible operating modes of the encoder and the decoder will be described below respectively.
At the transmitting end, the audio analog signal or the video analog signal is sampled, quantized, compressed and encoded by the encoder according to the MPEG-2 standard into an Elementary Stream (ES) which is an un-segmented consecutive stream. The ES is segmented into segments, corresponding headers are added to the segments, and the segments are packaged into a Packet Elementary Stream (PES) with packet head information including a Presentation Time Stamp (PTS) and a Decoding Time Stamp (DTS). A corresponding header is added to the PES packet to be transmitted, and then the PES packet is packaged into a 188-byte or 204-byte Transport Stream (TS) with a packet head including a Program Clock Reference (PCR) generated by sampling according to a time reference of the encoder, and a PES refers to an audio frame or a video frame.
At the receiving end, the decoder decodes the TS data packet into the audio frame or the video frame, extracts the PCR from the TS data packet, and recovers a System Time Clock (STC), which is a time reference of the decoder, from the extracted PCR, to thereby ensure the encoder and the decoder to be consistent in frequency and phase. The decoder extracts the PTS corresponding to the audio frame or the PTS corresponding to the video frame from the audio frame or the video frame. The audio frame or the video frame is played according to the PTS corresponding to the audio frame or the PTS corresponding to the video frame. The frame can be played particularly in such a way that the time difference between the time when the audio frame or the video frame is received, determined from the STC and the time indicated by the PTS is determined, and if the time difference is below a preset threshold, then the frame is played synchronously; or if the time difference is above the preset threshold, then the frame is played asynchronously. The frame needs to be played synchronously by counting each audio frame or video frame as a skipped frame or a duplicated frame. The number of skipped frames or duplicated frames can be calculated according to the time difference between the time, when the audio frame or the video frame is received, determined from the STC and the time indicated by the PTS, divided by the average time for which each frame is played. If the calculated number of skipped frames or duplicated frames is smaller than 1, then no skipped frame or duplicated frame will be processed; otherwise, the calculated number of skipped frames or duplicated frames are processed.